﻿using DBUtil;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;

namespace Jackletter.BlendAuth
{
    /// <summary>
    /// Token管理器
    /// </summary>
    public interface ITokenManager
    {
        /// <summary>
        /// 根据token管理器找到认证信息
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        BlendUser GetUser(string token);

        /// <summary>
        /// 认证配置对象
        /// </summary>
        BlendAuthenticationOptions Options { get; }

        /// <summary>
        /// 执行登陆操作,登陆成功后返回token
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        string SignIn(long userId, SignOptions options);

        /// <summary>
        /// 根据token执行注销操作
        /// </summary>
        /// <param name="token"></param>
        void SignOut(string token);

        void RefreshUser(BlendAuthModel entry);

        /// <summary>
        /// 根据指定用户Id执行注销操作
        /// </summary>
        /// <param name="userId">用户Id</param>
        void SignOut(long userId);
    }

    /// <summary>
    /// 登录时的属性
    /// </summary>
    public class SignOptions
    {
        /// <summary>
        /// 滑动窗口大小
        /// </summary>
        public TimeSpan? SlidingWindow { get; set; }

        /// <summary>
        /// 登录到的系统标识,可以使用类似"app."
        /// </summary>
        public string SystemCode { get; set; }

        /// <summary>
        /// 客户端表示,可以使用类似"android.huawei.meta"形式表示
        /// </summary>
        public string ClientCode { get; set; }
        public Dictionary<string, object> Properties { set; get; }
    }
}
